//
//  UserOrderCell.m
//  Wujin
//
//  Created by cz on 2016/12/11.
//  Copyright © 2016年 dong. All rights reserved.
//

#import "UserOrderCell.h"
#import "OrderModel.h"
@interface UserOrderCell ()
@property (weak, nonatomic) IBOutlet UILabel *orderId;
@property (weak, nonatomic) IBOutlet UILabel *orderTime;
@property (weak, nonatomic) IBOutlet UILabel *orderName;
@property (weak, nonatomic) IBOutlet UILabel *orderPhone;
@property (weak, nonatomic) IBOutlet UILabel *orderAddress;
@property (weak, nonatomic) IBOutlet UILabel *orderTotalPrice;


@end

@implementation UserOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.frame = CGRectMake(0, 0, SCREENBOUNDS.width, OrderListXibHeight);
    self.backgroundColor = [UIColor whiteColor];
    self.clipsToBounds = YES;
}

- (void)setOrderModel:(OrderModel *)orderModel {
    
    _orderModel = orderModel;
    self.orderId.text = orderModel.order_id;
    
    NSTimeInterval time = [orderModel.order_time doubleValue];
    NSDate *detailDate = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *changedDate = [dateFormatter stringFromDate:detailDate];
    
    self.orderTime.text = changedDate;
    self.orderName.text = orderModel.order_name;
    self.orderPhone.text = orderModel.order_phone;
    self.orderAddress.text = orderModel.order_address;
    
    NSInteger index = orderModel.order_totalPrice.length - 1;    
    NSString *str = [orderModel.order_totalPrice substringFromIndex:index];
    if ([str isEqualToString:@"元"]) {
        NSString *tempStr = [orderModel.order_totalPrice substringToIndex:index];
        CGFloat totalprice = [tempStr floatValue];
        self.orderTotalPrice.text = F(@"%.2f元", totalprice);
    }else{
        CGFloat totalprice = [orderModel.order_totalPrice floatValue];
        self.orderTotalPrice.text = F(@"%.2f元", totalprice);
    }
    
}

@end
